package com.test.mytest.swt;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;

public class Model {
	private List<User> allList = new ArrayList<>();
	private List<User> selectedList = new ArrayList<>();
	private List<User> checkedList = new ArrayList<>();
	private User u;

	final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

	public List<User> getAllList() {
		return allList;
	}

	public void setAllList(List<User> allList) {
		this.allList = allList;
		firePropertyChange("allList", null, null);
	}

	public List<User> getSelectedList() {
		return selectedList;
	}

	public void setSelectedList(List<User> selectedList) {
		this.selectedList = selectedList;
		firePropertyChange("selectedList", null, null);
	}

	public List<User> getCheckedList() {
		return checkedList;
	}

	public void setCheckedList(List<User> checkedList) {
		this.checkedList = checkedList;
		firePropertyChange("checkedList", null, null);
	}

	protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
		if (pcs != null) {
			pcs.firePropertyChange(propertyName, oldValue, newValue);
		} else {
			oldValue = newValue;
		}
	}

	public User getU() {
		return u;
	}

	public void setU(User u) {
		this.u = u;
		firePropertyChange("u", null, null);
	}

	public void addList(User user) {
		this.allList.add(user);
		firePropertyChange("allList", null, null);
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		if (this.pcs != null)
			this.pcs.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		if (this.pcs != null)
			this.pcs.removePropertyChangeListener(listener);
	}

	public PropertyChangeSupport getPropertyChangeSupport() {
		return pcs;
	}

	public void clearPropertyChangeListeners() {
		final PropertyChangeListener[] propertyChangeListeners = this.pcs.getPropertyChangeListeners();
		for (PropertyChangeListener propertyChangeListener : propertyChangeListeners) {
			this.pcs.removePropertyChangeListener(propertyChangeListener);
		}
	}
}
